import store from '@/store';
export default {
	// 检查网络
	checkNetwork() {
		uni.getNetworkType({
			complete: function(res) {
				console.log('获取网络状态', res.networkType)
				if (res.networkType == 'none') {
					uni.$u.toast('网络异常,请检查网络设置!');
					uni.reLaunch({
						url: '/pages/public/noNetWork'
					})
				} else {
					uni.reLaunch({
						url: '/pages/tabBarIndex/homeIndex'
					})
				}
			}
		});
	},
	// 退出登录页面
	backToLogin() {
		// 存当前页面的地址
		const currentPage = getCurrentPages()[getCurrentPages().length - 1];
		const params = {};
		// #ifdef H5
		params.route = `/${currentPage.$vm.route}`;
		params.query = currentPage.$vm.$mp && currentPage.$vm.$mp.query;
		// #endif
		// #ifdef MP
		params.route = `/${currentPage.$vm.__route__}`;
		params.query = currentPage.$vm.$mp && currentPage.$vm.$mp.query;
		// #endif
		// #ifdef APP-PLUS
		params.route = `/${currentPage.route}`;
		params.query = currentPage.options;
		// #endif
		store.commit('logout');
		uni.$u.route({
			type: "reLaunch",
			url: 'pages/public/login',
		});
	},
	// 比较版本号
	compareVersion(version1, version2) {
		// version1 < version2  结果：-1
		// version1 > version2  结果：1
		// version1 = version2  结果：0
		const arr1 = version1.split('.')
		const arr2 = version2.split('.')
		const length1 = arr1.length
		const length2 = arr2.length
		const minlength = Math.min(length1, length2)
		let i = 0
		for (i; i < minlength; i++) {
			let a = parseInt(arr1[i])
			let b = parseInt(arr2[i])
			if (a > b) {
				return 1
			} else if (a < b) {
				return -1
			}
		}
		if (length1 > length2) {
			for (let j = i; j < length1; j++) {
				if (parseInt(arr1[j]) != 0) {
					return 1
				}
			}
			return 0
		} else if (length1 < length2) {
			for (let j = i; j < length2; j++) {
				if (parseInt(arr2[j]) != 0) {
					return -1
				}
			}
			return 0
		}
		return 0
	},
}